package com.google.code.p.restrpc;

import java.util.HashMap;
import java.util.Map;

import com.google.code.p.restrpc.core.url.AsyncHeader;

public class RequestData {
    
    public static boolean isAsync(RequestData requestData) {
        if (requestData == null) {
            return false;
        }
        
        Map head = requestData.getHead();
        if (head == null) {
            return false;
        }
        
        AsyncHeader asyncHeader = (AsyncHeader) head.get(RpcRequest.ASYNC_KEY);
        if (asyncHeader == null) {
            return false;
        }
        
        return asyncHeader.isAsync();
    }
    
    public static String getRequestId(RequestData requestData) {
        Map head = requestData.getHead();
        if (head == null) {
            return null;
        }
        
        AsyncHeader asyncHeader = (AsyncHeader) head.get(RpcRequest.ASYNC_KEY);
        if (asyncHeader == null) {
            return null;
        }
        
        return asyncHeader.getRequestId();
    }
    
    private Map head = new HashMap();
    
    private Object body;
    
    /**
     * @return the header
     */
    public Map getHead() {
        return head;
    }
    
    /**
     * @param head
     *            the header to set
     */
    public void setHead(Map head) {
        this.head = head;
    }
    
    /**
     * @return the body
     */
    public Object getBody() {
        return body;
    }
    
    /**
     * @param body
     *            the body to set
     */
    public void setBody(Object body) {
        this.body = body;
    }
    
}
